﻿var User = Backbone.Model.extend({
    defaults: {
        'UserId': '',
        'UserName': '',
        'FullName': '',
        'Email': '',
        'Gender': true,
        'Mobile': '',
        'Telephone': '',
        'Password': '',
        'IsApproved': true,
        'Address': '',
        'nocache': (new Date()).toJSON()
    },
    /* Id Attribute */
    idAttribute: "UserName",
    /* model có id bang 0 là model mới url sẽ là add */
    isNew: function () {
        var id = this.get('UserId');
        if (!id || id == '') {
            return true;
        }
        return false;
    },
    /*
    lấy url
    */
    url: function () {
        if (this.isNew()) {
            return '/users/create_user';
        } else {
            return '/users/update_user';
        }
    }
});
var UserCollection = Backbone.Collection.extend({
    model: User
});

// User In Role Model
var UserInRole = Backbone.Model.extend({
    idAttribute: "RoleName",
    initialize: function () {
    },
    defaults: {
        UserName: '',
        RoleName: '',
        IsInRole: false
    },
    url: '/users/assign_role'
});
// User In Role Collection
var UserInRoleCollection = Backbone.Collection.extend({
    model: UserInRole
});